package com.paomi.client.activity.pay.adapter;

import android.content.Context;
import android.graphics.Typeface;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.makeramen.roundedimageview.RoundedImageView;
import com.paomi.client.R;
import com.paomi.client.activity.onlineSeat.model.SeatBean;
import com.paomi.client.fragment.first.model.TicketJson;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by pc on 2018/3/13.
 * 确认订单商品的列表适配
 */

public class ShopsListAdapter extends RecyclerView.Adapter<ShopsListAdapter.ViewHolder> {
    Context context;
    private TicketJson ticketJson;
    List<TicketJson> mlist = new ArrayList<>();
    List<SeatBean> seatBeans=null;//在线选座座位信息
    ShopsListAdapter.OnItemClick onClickListener;
    private Typeface mType;
    private Map<String,List<SeatBean>> seatBeanMap;

    public void OnItemClick(ShopsListAdapter.OnItemClick onClickListener) {
        this.onClickListener = onClickListener;
    }


    public ShopsListAdapter(Context context, Typeface typeface) {
        this.context = context;
        this.mType = typeface;
    }

    public void setData(TicketJson ticketJson,List<TicketJson> list, List<SeatBean> seatBeans, Map<String,List<SeatBean>> seatBeanMap) {
        this.mlist = list;
        this.seatBeans = seatBeans;
        this.seatBeanMap = seatBeanMap;
        this.ticketJson = ticketJson;
    }

    @Override
    public ShopsListAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ShopsListAdapter.ViewHolder(LayoutInflater.from(context).inflate(R.layout.item_pay_perform, parent, false));
    }

    @Override
    public void onBindViewHolder(final ShopsListAdapter.ViewHolder holder, final int position) {
        TicketJson ticket = mlist.get(position);
        holder.perform_title.setText(ticketJson.getName());
        Glide.with(context).load(ticketJson.getThumb()).into(holder.perform_iv);
        holder.tv_total.setText("¥" + ticket.getPayMoney());
        holder.num_tv.setText("X " + ticket.getPayNum());
        holder.perform_date.setText(ticketJson.getDate());
        holder.perform_address.setText(ticketJson.getVenue_name());
        if (ticketJson.getGood_type() == 0) {//是否在线选座 0 不选座 1选座
            holder.seat_tv.setText(context.getResources().getString(R.string.random_seat));
        }
        if(seatBeanMap!=null){//在线选座数据
            String stringType="";
            for(SeatBean seatBean:seatBeanMap.get(ticket.getPayMoney())){
//                if(seatBean.getColumns()<10){
//                    stringType +=seatBean.getRow()+"排"+seatBean.getColumns()+"号"+"\u3000\u3000"+seatBean.getPrice()+"¥"+"\n"+"\n";
//                }else{
//                    stringType +=seatBean.getRow()+"排"+seatBean.getColumns()+"号"+"\u3000\u3000"+seatBean.getPrice()+"¥"+"\n"+"\n";
//                }
//                stringType +=seatBean.getRow()+"排"+seatBean.getColumns()+"号"+"\u3000\u3000"+seatBean.getPrice()+"¥"+"\n"+"\n";
                stringType +=seatBean.getRow()+"排"+seatBean.getColumns()+"列"+"、";
            }
            holder.seat_tv.setText(stringType.substring(0,stringType.length()-1));
        }
    }

    @Override
    public int getItemCount() {
        return mlist.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.perform_iv)
        RoundedImageView perform_iv;
        @BindView(R.id.perform_title)
        TextView perform_title;
        @BindView(R.id.acc_txt)
        TextView acc_txt;
        @BindView(R.id.coupon_txt)
        TextView coupon_txt;
        @BindView(R.id.perform_date)
        TextView perform_date;
        @BindView(R.id.perform_address)
        TextView perform_address;
        @BindView(R.id.tv_total)
        TextView tv_total;
        @BindView(R.id.num_tv)
        TextView num_tv;
        @BindView(R.id.seat_tv)
        TextView seat_tv;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public interface OnItemClick {
//        void setOnItemClick(View view, int pos);
    }
}
